package com.yanqu.road.server.cmd.union.trade;

import com.yanqu.road.entity.union.trade.UnionTradeLog;
import com.yanqu.road.entity.union.trade.UnionTradeTeamData;
import com.yanqu.road.pb.union.UnionTradeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.UnionTradeMgr;
import com.yanqu.road.server.pb.UnionTradePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

//@Cmd(code = Protocol.S_UNION_TRADE_ROUTE_DATA_LOG_LIST, desc = "路线日志")
public class TradeLogDataListCmd extends AbstractCommand {

    private int routeId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionTradeProto.TradeLogDataListReqMsg reqMsg = UnionTradeProto.TradeLogDataListReqMsg.parseFrom(packet.getBytes());
        routeId = reqMsg.getRouteId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        String unionUid = player.getUserInfo().getUnionUid();
        if(StringUtils.isNullOrEmpty(unionUid)){
            ret = GameErrorCode.E_UNION_NO_JOIN_UNION;
        }
        UnionTradeProto.TradeLogDataListRespMsg.Builder respMsg = UnionTradeProto.TradeLogDataListRespMsg.newBuilder();
        UnionTradeTeamData unionTradeTeamData = UnionTradeMgr.getTeamDataByUnionUinAndRouteId(unionUid, routeId);
        if(unionTradeTeamData != null){
            List<UnionTradeLog> unionTradeLogList = unionTradeTeamData.getNewLogDataList();
            respMsg.addAllLogDataList(UnionTradePb.parseTradeLogDataTempMsgList(unionTradeLogList));
        }
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_UNION_TRADE_ROUTE_LOG_DATA_LIST, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
